from core.item import Item
from core.action import Action
from core.support import get_game, set_cutscene
from rooms.spring import Spring

class Canteen(Item):
    def __init__(self):
        Item.__init__(self, "canteen")    # do basic initialization for every item
        self.drinks_left = 0
        
        # build list of actions
        self.add_action(DrinkFrom)
        self.add_action(Fill)
    
    def get_description(self):
        if self.drinks_left > 0:
            return "canteen with water"
        else:
            return "empty canteen"

# define actions for this item

class DrinkFrom(Action):
    def __init__(self):
        Action.__init__(self, "drink_from")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Drink from canteen"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    
    # only works in basement. add cutscene
    def do_action(self,game,room,request):
        player = game.get_player()
        if player.death_count < 5:
            player.death_count = 5
        else:
            pass
        player.inventory['canteen'].drinks_left -= 1
        set_cutscene("You take a drink from the canteen.  You feel refreshed.")
        return
    
    def is_enabled(self):
        game = get_game()
        player = game.get_player()
        if player.inventory['canteen'].drinks_left > 0:
            return True
        else:
            return False
    
class Fill(Action):
    def __init__(self):
        Action.__init__(self, "fill")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Fill canteen"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    
    # only works in basement. add cutscene
    def do_action(self,game,room,request):
        player = game.get_player()
        player.inventory['canteen'].drinks_left = 5
        set_cutscene("You fill the canteen with water.")
        return
    
    def is_enabled(self):
        game = get_game()
        if game.history[-1] == game.get_room('spring', Spring):
            return True
        else:
            return False